#include <iostream>
#include <map>
#include <vector>
using namespace std;

class Bridge
{
private:
    map<int, int> macTable;
    int port1, port2;

public:
    Bridge() : port1(1), port2(2) {}

    void processFrame(int srcAddr, int srcPort, int destAddr)
    {
        macTable[srcAddr] = srcPort;

        int destPort;
        if (destAddr == 0xF)
        {              
            destPort = 3;
        }
        else if (macTable.find(destAddr) != macTable.end())
        {
            destPort = macTable[destAddr];
        }
        else
        {
            destPort = 3;
        }

        cout << "目的端口: ";
        if (destPort == 3)
        {
            cout << (srcPort == 1 ? port2 : port1) << " 和所有其他端口";
        }
        else
        {
            cout << destPort;
        }
        cout << endl;

        cout << "MAC地址表: ";
        for (auto &entry : macTable)
        {
            cout << "MAC " << hex << entry.first << " -> 端口 " << entry.second << "; ";
        }
        cout << endl;
    }
};

int main()
{
    Bridge bridge;
    vector<tuple<int, int, int>> frames = {
        {0x1, 1, 0x2},
        {0x2, 2, 0x1},
        {0x3, 1, 0xF}};

    for (auto &frame : frames)
    {
        int srcAddr, srcPort, destAddr;
        tie(srcAddr, srcPort, destAddr) = frame;
        cout << "处理帧: 源地址 " << hex << srcAddr << ", 源端口 " << srcPort
             << ", 目的地址 " << destAddr << endl;
        bridge.processFrame(srcAddr, srcPort, destAddr);
        cout << "-------------------" << endl;
    }
    return 0;
}